#!/bin/bash

while getopts d:o o;
do case $o in 
   'd' )
   device="$OPTARG"
   ;;
   ??)
   echo 'device error'
   exit 0
   ;;
   esac
done

if [ 'xx'$device == 'xx' ]; then
    device='eth0'
fi

ipaddr=`ifconfig $device |grep 'inet '|cut -d ':' -f2|awk '{print $1}'`
echo $ipaddr
